const http = require('http');
const url = require('url');
const queryString  = require("querystring");

var port = process.env.port || 1108;
http.createServer(function (req, res)
{
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    let obj = url.parse(req.url);

    let pathName = obj.pathname;
    let query = obj.query;
    let params = queryString.parse(query);
    let send_str = "";
    let method = req.method;

    switch(pathName)
    {
        case "login"://登录
            if(params)
            {

            }
            break;
        case "register"://注册

            break;
        case "query"://查询

            break;
    }
    res.end(JSON.stringify(obj,null,2));
    
}).listen(port);

//解析http请求
function parseGET(req, res)
{

}

function parsePOST(req, res)
{
    
}

/**统一处理请求 */
function parseReq(params, res)
{
    let pathName = params.pathName;
    let param_type = params.param_type;
    let param_value = params.param_value;
    switch(pathName)
    {
        case "login"://登录
            if(params)
            {

            }
            break;
        case "register"://注册

            break;
        case "query"://查询

            break;
    }

}
console.log("Server Started! Please visit http://127.0.0.1:" + port);